const http = require('http')
const path = require('path')
const fs = require('fs')
const url = require('url')

http.createServer((req,res)=>{
    const pathname = url.parse(req.url).pathname
    const html = fs.readFileSync(path.join(__dirname, 'index.html'))
    const img = fs.readFileSync(path.join(__dirname, 'test.png'))
    if (pathname === '/') {
        res.writeHeader(200, {
            'Content-Type': 'text/html'
        })
        res.write(html)
        res.end()
    } else {
        res.writeHeader(200, {
            'Content-Type': 'image/png'
        })
        res.write(img)
        res.end()
    }
}).listen(8888)